{% comment %}
/* Copyright 2009 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
{% endcomment %}
{% extends 'base.html' %}
{% block content %}
{% if no_posts_found or bad_date_request %}
  {% if no_posts_found %}
    Sorry, we couldn't find any posts.
  {% else %}
    Check the supplied date in the requested URL. It appears wrong.
  {% endif %}
{% else %}

{% comment %}User wants posts for a spcified date range.{% endcomment %}
{% if date_query %}
  {% for post in posts %}
  <p>
    <div class="post-title">
      <a
      href="/{{post.publish_date|date:"Y/m/d"}}/{{post.path|urlencode}}">
      {{post.title}}
      </a>
    </div>
    {% if blog.enable_postinfo %}
    <div class="post-info">
      <span class="post-publish">{{post.publish_date|date:"F j, Y" }}</span> -
      <span class="post-author">{{post.author.nickname}}</span>
      {% if blog.enable_comments %} -
      <span class="post-comments">
        <a
        href="/{{post.publish_date|date:"Y/m/d"}}/{{post.path|urlencode}}#comments">
        Comments
        </a>
      </span>
      {% endif %}
    </div>
    {% endif %}
    <div class="post-body">{{post.body}}</div>
    <span class="post-permalink">
      <a
      href="/{{post.publish_date|date:"Y/m/d"}}/{{post.path|urlencode}}">
      Permalink
      </a>
    </span>
    {% if blog.enable_comments %}
    <span class="post-comments">
      <a
      href="/{{post.publish_date|date:"Y/m/d"}}/{{post.path|urlencode}}#comments">
      Comments
      </a>
    </span>
    {% endif %}
  </p>
  {% endfor %}
{% else %}


  {% comment %}User wants a specific post.{% endcomment %}
  {% if post %}
    <p>
    <div class="post-title">
      <a
      href="/{{post.publish_date|date:"Y/m/d"}}/{{post.path|urlencode}}">
      {{post.title}}
      </a>
    </div>
    {% if blog.enable_postinfo %}
    <div class="post-info">
      <span class="post-publish">{{post.publish_date|date:"F j, Y" }}</span> -
      <span class="post-author">{{post.author.nickname}}</span> -
      {% if blog.enable_comments %}      
      <span class="post-comments">
        <a
        href="/{{post.publish_date|date:"Y/m/d"}}/{{post.path|urlencode}}#comments">
        Comments
        </a>
      </span>
      {% endif %}
    </div>
    {% endif %}
    <div class="post-body">{{post.body}}</div>
    </p>
    {% if blog.enable_comments %}
    <div id="post-comments"><a href="#" name="comments"></a>Comments:</div>

    {% comment %}
      Start the comments section.
    {% endcomment %}

    {% for comment in post_comments %}
    <div class="{% cycle dcomment,lcomment %}">
      <div class="comment-time">
        {{comment.date_time|date:"F j, Y @ P"}}
      </div>
      <a href="#" name="{{comment.key}}"></a>
      <div class="comment-author">
        {% if comment.author.url %}
        <a href="{{comment.author.url}}">
          {{comment.author.nickname}}
        </a>
        {% else %}
         {{comment.author.nickname}}
        {% endif %}
      said{% if comment.rely_to %}
        to <a
          href="#{{comment.reply_to.key}}">{{comment.reply_to.author.nickname}}
        </a>
      {% endif %},
      </div>
          <div class="comment-body">{{comment.body}}
          {% ifequal comment.status 'unreviewed' %}
          <br><span class="warning required">
            {% if is_admin %}
            Unreviewed
            {% else %}
            Awaiting review.
            {% endif %}
          </span>
          {% endifequal %}
        </div>
    </div>
    {% endfor %}
    <div class="divider">&nbsp;</div>

    {% comment %}
      Start comment form.
    {% endcomment %}

    {% if user %}
    <div id="comment-form">
      <form method="post">
        <input type="hidden" name="post" value="{{post.key|addslashes}}">
        <input type="hidden" name="author" value="{{user.key|addslashes}}">
        <div>
          <input
            type="text"
            name="nickname"
            class="text-input"
            value='{{user.nickname|default_if_none:"Anonymous"|addslashes}}'>
            (Nickname)
            {% if warnings.nickname %}
              <span class="warning">Your nickname shouldn't be blank.</span>
            {% endif %}
        </div>
        <div>
          <input
            type="text"
            name="url"
            class="text-input url-input"
            value='{{user.url|default_if_none:""|addslashes}}'> (Url)
            {% if warnings.url %}
            <span class="warning">
              Double check your url and don't forget the http://.
            </span>
            {% endif %}
        </div>
        {% if warnings.body %}
        <span class="warning">Don't forget to make your comment!</span><br>
        {% endif %}
        <textarea
          class="textarea-med"
          name=body>{{comment.body|escape}}</textarea>
        <div>
          <input type=submit name=new-comment value="Post Comment">
        </div>
      </form>
    </div>
    {% else %}
      You need to <a href='{{login_url}}'>login</a> to comment.
    {% endif %}
    {% endif %}
  {% else %}


  {% comment %}
    Couldn't find what the user wanted, so instead, we'll show some
    possible suggestions.
  {% endcomment %}


    {% if are_suggested_posts %}
    Couldn't find exactly what you asked for, but here are some suggestions:
    <br>
    {% else %}
      More than one match for your request:<br>
    {% endif %}

    {% for post in possible_posts %}
    <p>
    <div class="post-title">
      <a
      href="/{{post.publish_date|date:"Y/m/d"}}/{{post.path|urlencode}}">
      {{post.title}}
      </a>
    </div>
    <div class="post-info">
      <span class="post-publish">{{post.publish_date|date:"F j, Y" }}</span> -
      <span class="post-author">{{post.author.nickname}}</span> -
      <span class="post-comments">
        <a
        href="/{{post.publish_date|date:"Y/m/d"}}/{{post.path|urlencode}}#comments">
        Comments
        </a>
      </span>
    </div>
    <div class="post-body">{{post.body}}</div>
    <span class="post-permalink">
      <a
      href="/{{post.publish_date|date:"Y/m/d"}}/{{post.path|urlencode}}">
      Permalink
      </a>
    </span>
    <span class="post-comments">
      <a
      href="/{{post.publish_date|date:"Y/m/d"}}/{{post.path|urlencode}}#comments">
      Comments
      </a>
    </span>
    </p>
    {% endfor %}
  {% endif %}
  {% endif %}
{% endif %}
{% endblock %}